# 2.2 configConstant
# 1. Common Configurations
This method is used to configure JFinal constant values, such as the development mode constant "devMode". The following code presents some commonly used configurations:
public void configConstant(Constants me) {
// Configure development mode, true indicates development mode.
me.setDevMode(true);
// Configure AOP proxy to use cglib, otherwise, JFinal's default dynamic compilation proxy will be used.
me.setToCglibProxyFactory();
// Configure dependency injection.
me.setInjectDependency(true);
// Configure whether to inject dependencies into the superclass of the injected class.
me.setInjectSuperClass(false);
// Configure to use the slf4j logging system; otherwise, log4j will be used by default.
// You can also configure your extended logging system implementation with me.setLogFactory(...).
me.setToSlf4jLogFactory();
// Set the Json conversion factory implementation class, more details in Chapter 12.
me.setJsonFactory(new MixedJsonFactory());
// Configure the view type, the default is the JFinal enjoy template engine.
me.setViewType(ViewType.JFINAL_TEMPLATE);
// Configure the basic download path, the default is "download" under webapp.
me.setBaseDownloadPath(...);
// Configure the basic upload path, the default is "upload" under webapp.
me.setBaseUploadPath(...);
// Configure 404 and 500 pages.
me.setError404View("/common/404.html");
me.setError500View("/common/500.html");
// Enable parsing of json requests, a new feature in version 5.0.0.
me.setResolveJsonRequest(true);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
In development mode, JFinal will generate a report for every request, such as displaying the current request's URL, Controller, Method, and the parameters carried by the request.
# 2. Other Configurations
Other configurations:
public void configConstant(Constants me) {
// Configure encoding, the default is UTF8.
me.setEncoding("UTF8");
// Configure the date pattern used for converting Date type in JSON.
me.setJsonDatePattern("yyyy-MM-dd HH:mm");
// Configure whether to deny direct access to JSP. This is related to directly accessing .jsp files, and not related to renderJsp(xxx.jsp).
me.setDenyAccessJsp(true);
// Configure the maximum data size for file uploads, default is 10M.
me.setMaxPostSize(10 * 1024 * 1024);
// Configure the cache for CAPTCHA. Configuring a centralized shared cache can support distributed systems and clusters.
me.setCaptchaCache(...);
// Configure the separator for urlPara parameters, the default is "-".
me.setUrlParaSeparator("-");
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19